<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
	<th:block th:include="include :: header('修改')" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-perTemplateSpecRelation-edit" th:object="${perTemplateSpecRelation}">
			<div class="form-group">
				<input type="hidden" id="templateId" name="templateId" th:value="${templateId}">
				<input type="hidden" id="specId" name="specId"  th:field="*{specId}">
				<input type="hidden" id="relationId" name="relationId"  th:field="*{relationId}">
				<label class="col-sm-3 control-label">考核项名称：</label>
				<div class="col-sm-8">
					<select name="status" required class="form-control"  id="spec" th:onchange="change()" th:with="type=${@templateSpec.selectPerTemplateSpecListByType('11')}">
						<option value=""></option>
						<option th:each="tepmlate : ${type}"  th:selected="${tepmlate.specId == perTemplateSpecRelation.specId}" th:text="${tepmlate.specName}" th:value="${tepmlate.specId}" th:attr="specContent=${tepmlate.specContent}"></option>
					</select>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">考核项内容：</label>
				<div class="col-sm-8">
					<textarea id="specContent" name="specContent"  rows="16" class="col-sm-5 form-control" type="text" ></textarea>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">权重(%)：</label>
				<div class="col-sm-8">
					<input id="weight" name="weight" class="form-control" type="text" th:field="*{weight}">
				</div>
			</div>
		</form>
    </div>
    <div th:include="include::footer"></div>
    <script type="text/javascript">
		var prefix = ctx + "performance/perTemplateSpecRelation";
		$("#form-perTemplateSpecRelation-edit").validate({
			rules:{
				xxxx:{
					required:true,
				},
				rules:{
					xxxx:{
						required:true
					},
					weight:{
						number:true,
						range:[1,100]
					}

				},
			},
			focusCleanup: true
		});
		change();
		function submitHandler() {
			$.post( prefix + "/checkIsLegal",
					{"templateId":  $("#templateId").val(),
						"specId":$.common.trim($("#specId").val())
					},
					function(data){
						if(data=='1'){
							$.modal.alertError("该模板此绩效已经存在，请重新选择绩效考核项！");

						}else{
							if ($.validate.form()) {
								$.operate.save(prefix + "/edit", $('#form-perTemplateSpecRelation-edit').serialize());
							}
						}
					}
			);

	    }
		function change(){
			$('#specContent').text($('#spec option:selected').attr("specContent"));
			$('#specId').val($('#spec option:selected').val())
		}
	</script>
</body>
</html>
